﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using OutlookComponent;
using System.IO;

namespace MeetingMan
{
    public partial class FavorMeetingRooms : Form
    {
        public FavorMeetingRooms()
        {
            InitializeComponent();
            BindMeetingRooms();
        }

        private void BindMeetingRooms()
        {
            List<MeetingRoom> meetingRooms = OutlookHelper.ListAllManagedRooms();

            List<string> favorMeetingRooms = OutlookHelper.GetFavorMeetingRooms();
            //gvMeetingRooms.DataSource = meetingRooms;
            foreach (MeetingRoom room in meetingRooms)
            {
                gvMeetingRooms.Rows.Add(favorMeetingRooms.Contains(room.Name), room.Name);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            List<string> favorMeetingRooms = new List<string>();
            foreach (DataGridViewRow row in gvMeetingRooms.Rows)
            {
                DataGridViewCheckBoxCell checkbox = row.Cells[0] as DataGridViewCheckBoxCell;

                if ( checkbox.Value != null && (bool) checkbox.Value == true)
                {
                    DataGridViewTextBoxCell meetingRoomNameCell = row.Cells[1] as DataGridViewTextBoxCell;
                    favorMeetingRooms.Add( (string) meetingRoomNameCell.Value );
                }
            }
            OutlookHelper.SaveFavorMeetingRooms(favorMeetingRooms);
            this.Close();
        }

        
    }
}
